const app = getApp()

Page({
  data: {
    active: 0,
    html: ''
  },

  onLoad(opts) {
    console.log(opts)
    wx.showLoading({
      title: '加载中...',
    })
    let c_id = opts.c_id
    let c_name = opts.c_name
    wx.setNavigationBarTitle({
      title: c_name,
    })
    let access_token = wx.getStorageSync('access_token')
    wx.request({
      url: 'https://baokang.wshoto.com/wx/comdetail',
      data: {
        access_token: access_token,
        c_id: c_id
      },
      success: (res) => {
        console.log(res)
        if (res.data.code >= 500) {
          app.getLogin().then(function () {
            console.log('二次登录。。。')
          })
        }
        else if (res.data.code == 1) {
          this.setData({
            introduction: res.data.info.c_introduce,
            organs: res.data.info.organs,
            grid_introduce: res.data.info.grid_introduce,
            community: res.data.info.notice_list,
            newsList: res.data.info.news_list,
            work_idea:res.data.info.work_idea
          })
        }
      },
      complete: (res) => {
        wx.hideLoading()
      }
    })
  },

  loadDongTai() {
    let access_token = wx.getStorageSync('access_token')
    wx.request({
      url: 'https://baokang.wshoto.com/wx/newslist',
      data: {
        access_token: access_token,
        location: 'zhoukan',
        news_num: '-1'
      },
      success: (res) => {
        console.log(res)
        if (res.data.code >= 500) {
          app.getLogin().then(function () {
            console.log('二次登录。。。')
          })
        }
        else if (res.data.code == 1) {
          this.setData({
            newsList: res.data.list
          })
        }
      },
    })
  },

  // 选项卡  主要是通过判断e.target.id的值 设置对应的id显示
  switchNav(e) {
    wx.showLoading({
      title: '加载中...',
    })
    let id = e.currentTarget.id;
    this.setData({
      active: id
    })
    setTimeout(() => {
      wx.hideLoading()
    }, 500)
  },

  showMore(e) {
    console.log(e)
    let id = e.currentTarget.dataset.id
    this.setData({
      drop: true,
      select_id: id
    })
  },

  hideMore(e) {
    console.log(e)
    this.setData({
      drop: false,
      select_id: ''
    })
  },

  toNewsDetail(e) {
    let news_id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../news-details/news-details?news_id=' + news_id,
    })
  },
})